package com.dynamic.idea.quick.develop.plugin.entity.base02;

import com.dynamic.idea.quick.develop.plugin.enums.GeneralPackageStructTypeEnums;
import com.dynamic.idea.quick.develop.plugin.utils.FilePathUtils;
import com.dynamic.idea.quick.develop.plugin.utils.MyNumberUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * 通用的包结构
 */
public class GeneralPackageStruct implements Serializable {
    /**
     * 属于哪一个项目
     */
    private GeneralProjectStruct belongProjectStruct;

    /**
     * @see GeneralPackageStructTypeEnums
     * 类型:1-接口;2-实现;3-MapperXML;4-类
     */
    private Integer type;

    /**
     * java或MapperXML的基础包名,例如 cn.sdpjw.order
     */
    private String basePackageName;

    /**
     * 包名，例如 dao或mapper
     */
    private String packageName;

    /**
     * 生成的顺序 数字越小则越早生成
     */
    private Integer order;

    /**
     * 得到包全名,例如: cn.sdpjw.order.dao
     * @return
     */
    public String getPackageFullName(){
        return StringUtils.trim(getBasePackageName())+"."+StringUtils.trim(packageName);
    }

    /**
     * 得到当前项目java或MapperXML的包绝对地址
     * @return
     */
    public String getPackagePath(){
        if (MyNumberUtils.equals(type,GeneralPackageStructTypeEnums.MAPPER_XML.getValue())){
            return FilePathUtils.connectPath(belongProjectStruct.getSrcMainResourcesPath(),FilePathUtils.package2Path(getPackageFullName()));
        }
        return FilePathUtils.connectPath(belongProjectStruct.getSrcMainJavaPath(),FilePathUtils.package2Path(getPackageFullName()));
    }

    // get/set 方法
    public GeneralProjectStruct getBelongProjectStruct() {
        return belongProjectStruct;
    }

    public void setBelongProjectStruct(GeneralProjectStruct belongProjectStruct) {
        this.belongProjectStruct = belongProjectStruct;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getBasePackageName() {
        if (StringUtils.isNotBlank(basePackageName)){
            return basePackageName;
        }
        if (belongProjectStruct==null){
            return basePackageName;
        }
        if (MyNumberUtils.equals(type,GeneralPackageStructTypeEnums.MAPPER_XML.getValue())){
            basePackageName=belongProjectStruct.getBaseResourcePackageName();
        }else{
            basePackageName=belongProjectStruct.getBaseJavaPackageName();
        }
        return basePackageName;
    }

    public void setBasePackageName(String basePackageName) {
        this.basePackageName = basePackageName;
    }

    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public Integer getOrder() {
        return order;
    }

    public void setOrder(Integer order) {
        this.order = order;
    }
}
